#include <iostream>
#include <algorithm>

using namespace std;

const char s[10] = "abcde";

int visit[5] = {0};
string ans;

void dfs(int n)
{
    if (n == 5)
    {
        for (int i = 0; i < 5; ++i)
        {
            cout << ans[i] << " ";
        }
        cout << endl;
    }

    for (int i = 0; i < 5; ++i)
    {
        if (0 == visit[i])
        {
            visit[i] = 1;
            ans[n] = s[i];
            dfs(n + 1);
            visit[i] = 0;
        }
    }
}

void print_permutation()
{
    do
    {
        for (int i = 0; i < 5; ++i)
        {
            cout << s[i] << "";
        }
    }while(next_permutation(s, s + 5));
}

int main()
{
    print_permutation();
    return 0;
}
